package com.zhou.common.mybatis.template.shiro.zhou.handler;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.event.EventListener;
import org.springframework.session.data.redis.RedisIndexedSessionRepository;
import org.springframework.session.events.SessionDeletedEvent;
import org.springframework.session.events.SessionExpiredEvent;
import org.springframework.stereotype.Component;

@Component
public class MyEventHandle {

    @Autowired
    private RedisIndexedSessionRepository sessionRepository;

    /**
     * 参数任意(为Object）的时候所有事件都会监听到
     * 所有，该参数事件，或者其子事件（子类）都可以接收到
     */
    @EventListener
    public void handleSessionExpired(SessionExpiredEvent event){
        System.out.println("MyEventHandle 接收到事件：" + event.getClass());
        //sessionRepository.deleteById(event.getSessionId());
    }

    @EventListener
    public void handleSessionDeleted(SessionDeletedEvent event){
        System.out.println("MyEventHandle 接收到事件：" + event.getClass());
    }


    //第二种写法

/*    public class MyApplicationListener implements ApplicationListener<MyApplicationEvent>{
        @Override
        public void onApplicationEvent(MyApplicationEvent event) {
            System.out.println("接收到事件："+event.getClass());
        }
    }*/

}
